import { isValidKey } from '@/utils/common';
import { getCurrentLocale } from '@/utils/locale';
// 公共
import common from './common';
import docs from './docs';
import footer from './footer';
import header from './header';
import home from './home';
import my from './my';
import notification from './notification';
import response from './response';
import sig from './sig';
import validator from './validator';
import cookie from './cookie';

const messages = {
  zh: {
    // 公共
    common: common.zh,
    header: header.zh,
    footer: footer.zh,
    docs: docs.zh,
    home: home.zh,
    my: my.zh,
    notification: notification.zh,
    response: response.zh,
    sig: sig.zh,
    validator: validator.zh,
    cookie: cookie.zh,
  },
  en: {
    // 公共
  },
};

const t = (() => {
  const msg = messages[getCurrentLocale()];

  return (val: string) => {
    const [category, key] = val.split('.');
    if (isValidKey(category, msg) && isValidKey(key, msg[category])) {
      return msg[category][key];
    }
    return val;
  };
})();

const $t = t;

export { t, $t, messages };
